# -*- coding: utf-8 -*-
"""
    Time    : 2020/12/25 10:20 下午
    Author  : Thinkgamer
    File    : add01-循环有序数组查找指定值.py
    Desc    : 循环有序数组查找指定值
"""


def find(nums, target):
	left = 0
	right = len(nums) - 1
	while left <= right:
		mid = (left + right) // 2
		if nums[mid] == target:
			return mid
		# 左边有序
		elif nums[mid] > nums[left]:
			# 判断 target 是否在有序的区间内
			if nums[mid] > target >= nums[left]:
				right = mid - 1
			else:
				left = mid + 1
		# 右边有序
		else:
			# 如果target 在有序的区间内
			if nums[right] >= target > nums[mid]:
				left = mid + 1
			else:
				right = mid - 1
	return None


nums = [5, 6, 7, 8, 9, 1, 2]
target = 1
result = find(nums, target)
print(result)